#include "judge.hpp"
/*std::bitset<1444> *map*/
Judge::Judge(std::bitset<32>  ****map2, bool double3, bool latePrise) : width(19), height(19), size(1444), maskPriseSize(8), maskWinSize(20), maskDouble3Size(4500), player(1)
{
	this->double3 = double3;
	this->latePrise = latePrise;
	this->winner = false;
	this->scorePlayer1 = 0;
	this->scorePlayer2 = 0;
	this->map2 = map2;
	//this->initMask();
	//this->initMask2();
}

int		Judge::getWinner()
{
	if (this->winner == false)
		return -1;
	if (this->isWinner == true)
		return 0;
	return 1;
}

int*	Judge::getScores()
{
	int* tab = new int[2];
	tab[0] = this->scorePlayer1;
	tab[1] = this->scorePlayer2;
	return tab;
}

void	Judge::initMask()
{
	/*
		MASK PRISE
	*/
	int i = 0;
	this->maskPriseOffset = new int[this->maskPriseSize];
	this->maskPriseJ1 = new std::bitset<1444>[this->maskPriseSize];
	this->maskPriseJ2 = new std::bitset<1444>[this->maskPriseSize];
	/*
		122X
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("0100001100111000"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("0010010101011000"));
	this->maskPriseOffset[i++] = 0;
	/*
		X221
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("1000001100110100"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("1000010101010010"));
	this->maskPriseOffset[i++] = 12;
	/*
		1
		2
		2
		X
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("0100000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("0010000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskPriseOffset[i++] = 0;
	/*
		X
		2
		2
		1
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("1000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("1000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskPriseOffset[i++] = 228;
	/*
		1
		 2
		  2
		   X
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("0100000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("0010000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskPriseOffset[i++] = 0;
	/*
		X
		 2
		  2
		   1
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("1000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("1000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskPriseOffset[i++] = 240;
	/*
		   1
		  2
		 2
		X
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("0100000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000001000000000000000"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("0010000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000001000000000000000"));
	this->maskPriseOffset[i++] = 12;
	/*
		   X
		  2
		 2
		1
	*/
	this->maskPriseJ1[i] = std::bitset<1444>(std::string("1000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000100000000000000"));
	this->maskPriseJ2[i] = std::bitset<1444>(std::string("1000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000010000000000000"));
	this->maskPriseOffset[i++] = 228;
	/*
		MASK WIN
	*/
	i = 0;
	this->maskWinOffset = new int[this->maskWinSize];
	this->maskWinJ1 = new std::bitset<1444>[this->maskWinSize];
	this->maskWinJ2 = new std::bitset<1444>[this->maskWinSize];
	/*
		1111X
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000101010101011000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100011001100111000"));
	this->maskWinOffset[i++] = 0;
	/*
		111X1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000101010110010100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100011001110010010"));
	this->maskWinOffset[i++] = 4;
	/*
		11X11
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000101100101010100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100011100100110010"));
	this->maskWinOffset[i++] = 8;
	/*
		1X111
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01001001010101010100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00101001001100110010"));
	this->maskWinOffset[i++] = 12;
	/*
		X1111
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("10000101010101010100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("10000011001100110010"));
	this->maskWinOffset[i++] = 16;
	/*
		1
		1
		1
		1
		X
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskWinOffset[i++] = 0;
	/*
		1
		1
		1
		X
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 76;
	/*
		1
		1
		X
		1
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 152;
	/*
		1
		X
		1
		1
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 228;
	/*
		X
		1
		1
		1
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("10000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("10000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 304;
	/*
		1
		 1
		  1
		   1
		    X
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000001000"));
	this->maskWinOffset[i++] = 0;
	/*
		1
		 1
		  1
		   X
		    1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 80;
	/*
		1
		 1
		  X
		   1
		    1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 160;
	/*
		1
		 X
		  1
		   1
		    1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("010000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("001000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 240;
	/*
		X
		 1
		  1
		   1
		    1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("100000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("100000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000010"));
	this->maskWinOffset[i++] = 320;
	/*
		    1
		   1
		  1
		 1
		X
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000010000000000000000000"));
	this->maskWinOffset[i++] = 16;
	/*
		    1
		   1
		  1
		 X
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000"));
	this->maskWinOffset[i++] = 88;
	/*
		    1
		   1
		  X
		 1
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000"));
	this->maskWinOffset[i++] = 160;
	/*
		    1
		   X
		  1
		 1
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("01000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("00100000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000"));
	this->maskWinOffset[i++] = 232;
	/*
		    X
		   1
		  1
		 1
		1
	*/
	this->maskWinJ1[i] = std::bitset<1444>(std::string("10000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000"));
	this->maskWinJ2[i] = std::bitset<1444>(std::string("10000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000000000000000"));
	this->maskWinOffset[i++] = 304;
	/*
		DOUBLE 3
	*/
	if (this->double3 == true)
	{
		i = 0;
		int j = 0;
		std::cout << j << " lines have been parsed !" << std::endl;
		this->maskDouble3Offset = new int[this->maskDouble3Size];
		this->maskDouble3J1 = new std::bitset<1444>[this->maskDouble3Size];
		this->maskDouble3J2 = new std::bitset<1444>[this->maskDouble3Size];
		std::ifstream fichier("../Ressources/maskDouble3_full.txt", std::ios::in);
		if(fichier)
        {
            std::string ligne;
			while(std::getline(fichier, ligne))
			{
				if (j % 3 == 0)
					this->maskDouble3J1[i] = std::bitset<1444>(ligne);
				if (j % 3 == 1)
					this->maskDouble3J2[i] = std::bitset<1444>(ligne);
				if (j % 3 == 2)
					this->maskDouble3Offset[i++] = atoi(ligne.c_str());
				j++;
			}
            fichier.close();
        }
        else
            std::cerr << "Impossible d'ouvrir le fichier !" << std::endl;
		std::cout << "Loading complete !" << std::endl;
		std::cout << j << " lines have been parsed !" << std::endl;
		std::cout << i << " masks have been added !" << std::endl;
	}
}

bool	Judge::iaPlay(int player, int x, int y, std::bitset<1444> *map)
{
	if (player == 1)
		return this->tryPlayJ1(x * 4 + y * 76, map);
	return this->tryPlayJ2(x * 4 + y * 76, map);
}

bool   Judge::play2(int player, int x, int y)
{
		if (player == 1)
		return tryPlay2J1(x, y, this->map2);
	return tryPlay2J2(x, y, this->map2);
}

bool Judge::tryPlay2J1(int x, int y, std::bitset<32>   ****map)
{
	return true;
}

bool Judge::tryPlay2J2(int x, int y, std::bitset<32>   ****map)
{
	//if (this->double3 == true)
	//{
	//	int i = 0;
	//	while (i < this->maskDouble3Size)
	//	{
	//		//(this->maskDouble3J1[i] & *this->map >> pos - this->maskDouble3Offset[i]) == this->maskDouble3J1[i]
	//		if (map[x][y][0])
	//		{
	//			std::cout << ">> DOUBLE 3 !" << std::endl;
	//			return false;
	//		}
	//		i++;
	//	}
	//	i = 0;
	//}
	//if ((*map[x][y][0] >> 30))
	return true;
}

bool	Judge::play(int player, int x, int y)
{
	if (player == 1)
		return tryPlayJ1(x * 4 + y * 76, this->map);
	return tryPlayJ2(x * 4 + y * 76, this->map);
}

bool	Judge::tryPlayJ1(int pos, std::bitset<1444> *map)
{
	if (this->map->test(pos + 3) == false)
		return false;
	int i = 0;
	if (this->double3 == true)
	{
		while (i < this->maskDouble3Size)
		{
			if ((this->maskDouble3J1[i] & *this->map >> pos - this->maskDouble3Offset[i]) == this->maskDouble3J1[i])
			{
				std::cout << ">> DOUBLE 3 !" << std::endl;
				return false;
			}
			i++;
		}
		i = 0;
	}
	while (i < this->maskPriseSize)
	{
		if ((this->maskPriseJ1[i] & *this->map >> pos - this->maskPriseOffset[i]) == this->maskPriseJ1[i])
		{
			std::cout << "J1 PRISE " << i << std::endl;
			if (i == 0)
			{
				this->map->reset(pos + 5);
				this->map->set(pos + 7);
				this->map->reset(pos + 9);
				this->map->set(pos + 11);
			}
			else if (i == 1)
			{
				this->map->reset(pos - 3);
				this->map->set(pos - 1);
				this->map->reset(pos - 7);
				this->map->set(pos - 5);
			}
			else if (i == 2)
			{
				this->map->reset(pos + 77);
				this->map->set(pos + 79);
				this->map->reset(pos + 153);
				this->map->set(pos + 155);
			}
			else if (i == 3)
			{
				this->map->reset(pos - 75);
				this->map->set(pos - 73);
				this->map->reset(pos - 151);
				this->map->set(pos - 149);
			}
			else if (i == 4)
			{
				this->map->reset(pos + 81);
				this->map->set(pos + 83);
				this->map->reset(pos + 161);
				this->map->set(pos + 163);
			}
			else if (i == 5)
			{
				this->map->reset(pos - 79);
				this->map->set(pos - 77);
				this->map->reset(pos - 159);
				this->map->set(pos - 157);
			}
			else if (i == 6)
			{
				this->map->reset(pos + 73);
				this->map->set(pos + 75);
				this->map->reset(pos + 145);
				this->map->set(pos + 147);
			}
			else if (i == 7)
			{
				this->map->reset(pos - 71);
				this->map->set(pos - 69);
				this->map->reset(pos - 143);
				this->map->set(pos - 141);
			}
			this->scorePlayer1 += 2;
			if (this->scorePlayer1 >= 10)
			{
				this->winner = true;
				this->isWinner = true;
			}
		}
		i++;
	}
	i = 0;
	while (i < this->maskWinSize)
	{
		if ((this->maskWinJ1[i] & *this->map >> pos - this->maskWinOffset[i]) == this->maskWinJ1[i])
		{
			std::cout << "J1 WINS " << i << std::endl;
			this->winner = true;
			this->isWinner = true;
		}
		i++;
	}
	this->map->set(pos + 3, false);
	this->map->set(pos + 2);
	this->player = 2;
	return true;
}

bool	Judge::tryPlayJ2(int pos, std::bitset<1444> *map)
{
	if (this->map->test(pos + 3) == false)
		return false;
	int i = 0;
	if (this->double3 == true)
	{
		while (i < this->maskDouble3Size)
		{
			if ((this->maskDouble3J2[i] & *this->map >> pos - this->maskDouble3Offset[i]) == this->maskDouble3J2[i])
			{
				std::cout << "DOUBLE 3 !" << std::endl;
				return false;
			}
			i++;
		}
		i = 0;
	}
	while (i < this->maskPriseSize)
	{
		if ((this->maskPriseJ2[i] & *this->map >> pos - this->maskPriseOffset[i]) == this->maskPriseJ2[i])
		{
			std::cout << "J2 PRISE" << std::endl;
			if (i == 0)
			{
				this->map->reset(pos + 6);
				this->map->set(pos + 7);
				this->map->reset(pos + 10);
				this->map->set(pos + 11);
			}
			else if (i == 1)
			{
				this->map->reset(pos - 2);
				this->map->set(pos - 1);
				this->map->reset(pos - 6);
				this->map->set(pos - 5);
			}
			else if (i == 2)
			{
				this->map->reset(pos + 78);
				this->map->set(pos + 79);
				this->map->reset(pos + 154);
				this->map->set(pos + 155);
			}
			else if (i == 3)
			{
				this->map->reset(pos - 74);
				this->map->set(pos - 73);
				this->map->reset(pos - 150);
				this->map->set(pos - 149);
			}
			else if (i == 4)
			{
				this->map->reset(pos + 82);
				this->map->set(pos + 83);
				this->map->reset(pos + 162);
				this->map->set(pos + 163);
			}
			else if (i == 5)
			{
				this->map->reset(pos - 78);
				this->map->set(pos - 77);
				this->map->reset(pos - 158);
				this->map->set(pos - 157);
			}
			else if (i == 6)
			{
				this->map->reset(pos + 74);
				this->map->set(pos + 75);
				this->map->reset(pos + 146);
				this->map->set(pos + 147);
			}
			else if (i == 7)
			{
				this->map->reset(pos - 70);
				this->map->set(pos - 69);
				this->map->reset(pos - 142);
				this->map->set(pos - 141);
			}
			this->scorePlayer2 += 2;
			if (this->scorePlayer2 >= 10)
			{
				this->winner = true;
				this->isWinner = false;
			}
		}
		i++;
	}
	i = 0;
	while (i < this->maskWinSize)
	{
		if ((this->maskWinJ2[i] & *this->map >> pos - this->maskWinOffset[i]) == this->maskWinJ2[i])
		{
			std::cout << "J2 WINS" << std::endl;
			this->winner = true;
			this->isWinner = false;
		}
		i++;
	}
	this->map->set(pos + 3, false);
	this->map->set(pos + 1);
	this->player = 1;
	return true;
}

bool	Judge::setMap(int x, int y)
{
	if (x > 18 || y > 18 || x < 0 || y < 0)
		return false;
	try
	{
		int pos = x * 3 + y * 57;
		this->map->set(pos);
		this->map->set(pos + 1);
		this->map->set(pos + 2);
		return true;
	}
	catch (const std::out_of_range &)
	{
		return false;
	}
}

void	Judge::affBitset(std::string aff)
{
	int i = 76;
	while (i < 1444)
	{
		aff.insert(i, "\n");
		i+=77;
	}
	std::cout << aff << std::endl;
}

void    Judge::affMap2()
{
	int i,j;
	std::cout << "map : " << std::endl;
	for (i=0;i<19;++i) 
	{
		for (j=0;j<19;++j) 
			std::cout << this->map2[i][j][0]->to_string() << "|";
		std::cout << std::endl;
	}
}

void	Judge::affMap()
{
	std::string aff = this->map->to_string();
	int i = 76;
	while (i < 1444)
	{
		aff.insert(i, "\n");
		i+=77;
	}
	std::cout << aff << std::endl;
}

void	Judge::resetMap()
{
	this->map->reset();
	int i = 0;
	while (i < this->size)
	{
		if (i % 76 != 0 && i % 76 != 72)
			this->map->set(i);
		this->map->set(i + 3);
		i += 4;
	}
}

void	Judge::resetGame()
{
	this->resetMap();
	this->scorePlayer1 = 0;
	this->scorePlayer2 = 0;
	this->winner = false;
}

int		Judge::playerTurn()
{
	return this->player;
}